package demo03;

import java.util.function.Consumer;

/*
 *  Consumer接口案例：格式化打印信息
 */
public class Demo05ConsumerPrint {
    public static void main(String[] args) {
        String[] strings = { "土司鸡,18", "老虎,20", "粹花,1", "小飞棍,来咯" };
        // 通过split方法切割字符串，获得数组每个字符串分割的两个部分，然后分别打印
        printString(strings, string -> System.out.print(string.split(",")[0] + " "),
                string -> System.out.println(string.split(",")[1]));
        /*
         *  土司鸡 18
         *  老虎 20
         *  粹花 1
         *  小飞棍 来咯
         */
    }

    public static void printString(String[] strings, Consumer<String> consumer1, Consumer<String> consumer2) {
        for (String string : strings) { // 遍历数组的每个字符串元素，进行消费操作
            consumer1.andThen(consumer2).accept(string);
        }
    }
}
